package com.virgo.demo.support.service.impl;

import com.virgo.demo.support.service.AppService;
import com.virgo.demo.support.service.ConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
@RequiredArgsConstructor
public class AppServiceImpl implements AppService {

    private final ConfigService configService;

    /**
     * 拼接静态资源地址
     * @param path String
     * @return String
     */
    @Override
    public String getStaticUrl(String path) {
        if (ObjectUtils.isEmpty(path)) {
            return "";
        }
        if (path.startsWith("http://") || path.startsWith("https://")) {
            return path;
        }
        String domain = configService.getConfig("static_domain");
        String version = configService.getConfig("static_version");
        return domain + path + "?_v=" + version;
    }

}